﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;
using KorleBu.Report_Files;
using KorleBu.Application_Classes;

namespace KorleBu
{
    public partial class Reports : System.Web.UI.Page
    {
        #region Class State Variables

        /// <summary>
        /// Dataset object, used for housing user method calls results.
        /// </summary>
        DataSet ds = new DataSet();
        /// <summary>
        /// Presentation object that accesses the presentation object classes methods.
        /// Used for accessing business methods for the user page.
        /// </summary>
        Presentation presentation = new Presentation();
        /// <summary>
        /// Data source object that will be used to populate the 
        /// respective report viewers for a given report.
        /// </summary>
        ReportDataSource dataSource;
        /// <summary>
        /// Represents the current user who has accessed this page.  
        /// This string will be placed on each date report.
        /// </summary>
        //string preparedBy = GetFirstName() + " " + GetLastName();
        string preparedBy = "";
        /// <summary>
        /// Place holder string for try parsed start dates, used heavily when checking whether 
        /// the start dates selected for item adjustments report are valid dates. 
        /// </summary>
        DateTime startDate;
        /// <summary>
        /// Place holder string for try parsed end dates, used heavily when checking whether 
        /// the end dates selected for item adjustments report are valid dates.
        /// </summary>
        DateTime endDate;
        #endregion

        ////Jason Vance 10-31-12; Lazy initialize the label found on MasterPage.Master
        //private Label _lblMasterError;
        //private Label lblMasterError
        //{
        //    get
        //    {
        //        if (_lblMasterError == null)
        //            _lblMasterError = (Label)Master.FindControl("lblMasterError");
        //        return _lblMasterError;
        //    }
        //}

        #region Page Load

        /// <summary>
        /// Page load method, ran at the beginning of the reports page startup load.
        /// Checks to see if the user actually logged in and if they have CEO, GM, Store Manager, Store Keeper, or Accounting privileges, 
        /// if not they are redirected to the login page or the home page depending on the condition.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            //if the user didn't log in, but browsed to this page redirect them to the login page.
            if (GetSessionID() == null || GetSessionID() == "")
            {
                Response.Redirect("~/Login.aspx", true);
            }

            //if the user doesn't have the correct privileges send them back to the home page
            if (GetIsCEO() == false && GetIsGeneralManager() == false && GetIsStoreManager() == false && GetIsStoreKeeper() == false && GetIsAccounting() == false)
            {
                Response.Redirect("~/Home.aspx", true);
            }
            lblLoggedInUser.Text = "You are logged in as " + GetFirstName() + " " + GetLastName();
            if (!IsPostBack)
            {
                TabContainer_ActiveTabChanged(TabContainer, null);  //initializes the tab index to the starting index
                preparedBy = GetFirstName() + " " + GetLastName();

                //show a message for pending tasks if the given user has tasks to do.  
                //This should only apply to store managers, general managers, CEOs, and Procurement
                if (GetIsStoreManager())
                {
                    ds = presentation.GetPendingRequests(GetStoreID());
                    if (ds.Tables.Count > 0) // If the method returned successfully
                    {
                        if (ds.Tables[0].Rows[0][0].ToString() != "") // if errors have occurred
                        {
                            //lblMasterError.Text = ds.Tables[0].Rows[0][0].ToString(); // Error message
                        }
                        else
                        {
                            //lblSideBarContent.Text = "**You have pending satellite store requests to handle.**";
                        }
                    }
                }
                else if (GetIsGeneralManager())
                {
                    ds = presentation.GetRequisitionsByPendingStatus();
                    if (ds.Tables.Count > 0) // If the method returned successfully
                    {
                        if (ds.Tables[0].Rows[0][0].ToString() != "") // if errors have occurred
                        {
                            //lblMasterError.Text = ds.Tables[0].Rows[0][0].ToString(); // Error message
                        }
                        else
                        {
                            //lblSideBarContent.Text = "**You have pending requisitions to handle.**";
                        }
                    }
                }
                else if (GetIsCEO())
                {
                    ds = presentation.GetRequisitionsByGMStatus();
                    if (ds.Tables.Count > 0) // If the method returned successfully
                    {
                        if (ds.Tables[0].Rows[0][0].ToString() != "") // if errors have occurred
                        {
                            //lblMasterError.Text = ds.Tables[0].Rows[0][0].ToString(); // Error message
                        }
                        else
                        {
                            //lblSideBarContent.Text = "**You have pending requisitions to handle.**";
                        }
                    }
                }
                else if (GetIsProcurement())
                {
                    ds = presentation.GetRequisitionsByCEOStatus();
                    if (ds.Tables.Count > 0) // If the method returned successfully
                    {
                        if (ds.Tables[0].Rows[0][0].ToString() != "") // if errors have occurred
                        {
                            //lblMasterError.Text = ds.Tables[0].Rows[0][0].ToString(); // Error message
                        }
                        else
                        {
                            //lblSideBarContent.Text = "**You have pending requisition orders to handle.**";
                        }
                    }
                }

                //load up the year drop downs

                ds = presentation.GetYears();
                ddlMRYear.DataSource = ds.Tables[0];
                ddlMRYear.DataTextField = "year";
                ddlMRYear.DataValueField = "year";
                ddlMRYear.DataBind();

                ddlQRYear.DataSource = ds.Tables[0];
                ddlQRYear.DataTextField = "year";
                ddlQRYear.DataValueField = "year";
                ddlQRYear.DataBind();

                ddlYear.DataSource = ds.Tables[0];
                ddlYear.DataTextField = "year";
                ddlYear.DataValueField = "year";
                ddlYear.DataBind();

                //disable generate report buttons and necessary drop downs
                btnGenMonthReport.Enabled = false;
                btnGenQuarterReport.Enabled = false;
                ddlMRYear.Enabled = false;
                ddlQRYear.Enabled = false;
                ddlAdvFilter.Enabled = false;

                //hide all reports and their containers
                divCurInvAll.Style.Value = "display:none;float:left;";
                divCurInvItem.Style.Value = "display:none;float:left;";
                divCurInvSub.Style.Value = "display:none;float:left;";
                divCurInvCat.Style.Value = "display:none;float:left;";
                divMonthInv.Style.Value = "display:none;float:left;";
                divQuarterInv.Style.Value = "display:none;float:left;";
                divYearInv.Style.Value = "display:none;float:left;";
                divItemAdjust.Style.Value = "display:none;float:left;";
                rvCurInvAll.Visible = false;
                rvCurInvItem.Visible = false;
                rvCurInvSub.Visible = false;
                rvCurInvCat.Visible = false;
                rvMonthInv.Visible = false;
                rvQuarterInv.Visible = false;
                rvYearInv.Visible = false;
                rvItemAdjust.Visible = false;

                //set all drop downs to original starting index, and clear out text boxes
                ddlAdvFilter.SelectedIndex = 0;
                ddlFilter.SelectedIndex = 0;
                ddlMRYear.SelectedIndex = 0;
                ddlQRYear.SelectedIndex = 0;
                ddlYear.SelectedIndex = 0;
                ddlMonth.SelectedIndex = 0;
                ddlQuarter.SelectedIndex = 0;
                txtStartDate.Text = "";
                txtEndDate.Text = "";

                //clear out any success or error messages for that tab form.
                lblMasterError.Text = "";    //clear out any error messages
                lblMasterError.Text = "";    //clear out any error messages
                lblMasterError.Text = "";   //clear out any error messages
            }
        }

        #endregion

        #region Active Tabs Changed

        /// <summary>
        /// Method handles the changing of tabs.  The far left tab starts at index 0.
        /// Place any code in the designated tab that needs to be changed dynamically each time a the tab is clicked.
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">EventArgs</param>
        protected void TabContainer_ActiveTabChanged(object sender, EventArgs e)
        {
            try
            {
                if (TabContainer.ActiveTabIndex == 0) { lblMasterError.Text = ""; }

                if (TabContainer.ActiveTabIndex == 1) { lblMasterError.Text = ""; }

                if (TabContainer.ActiveTabIndex == 2) { lblMasterError.Text = ""; }
            }
            catch
            {
                throw;
            }
            finally
            {

            }
        }
        #endregion

        #region Buttons

        /// <summary>
        /// Method handles the click functionality for generating a monthly report.
        /// Given a year and month, a specific monthly report is generated for inventory items.
        /// This data source is then assigned to a report viewer in order to generate and display the report.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnGenMonthReport_OnClick(object sender, EventArgs e)
        {
            lblMasterError.Text = "";    //clear out any error messages

            //hide all reports and their containers
            divYearInv.Style.Value = "display:none;float:left;";
            divMonthInv.Style.Value = "display:none;float:left;";
            divQuarterInv.Style.Value = "display:none;float:left;";
            rvYearInv.Visible = false;
            rvMonthInv.Visible = false;
            rvQuarterInv.Visible = false;

            //Generate monthly report
            generateReport("MonthInv");

            //re-enable all drop downs for other reports and disable this generate report button and year drop down.
            //btnGenMonthReport.Enabled = false;
            btnGenYearReport.Enabled = true;
            ddlMRYear.Enabled = false;
            ddlQuarter.Enabled = true;
            ddlYear.Enabled = true;
        }

        /// <summary>
        /// Method handles the click functionality for generating a quarterly report.
        /// Given a year and quarter, a specific quarterly report is generated for inventory items.
        /// This data source is then assigned to a report viewer in order to generate and display the report.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnGenQuarterReport_OnClick(object sender, EventArgs e)
        {
            lblMasterError.Text = "";    //clear out any error messages

            //hide all reports and their containers
            divYearInv.Style.Value = "display:none;float:left;";
            divMonthInv.Style.Value = "display:none;float:left;";
            divQuarterInv.Style.Value = "display:none;float:left;";
            rvYearInv.Visible = false;
            rvMonthInv.Visible = false;
            rvQuarterInv.Visible = false;

            //Generate quarterly report
            generateReport("QuarterInv");

            //re-enable all drop downs for other reports and disable this generate report button and year drop down.
            //btnGenQuarterReport.Enabled = false;
            btnGenYearReport.Enabled = true;
            ddlQRYear.Enabled = false;
            ddlMonth.Enabled = true;
            ddlYear.Enabled = true;
        }

        /// <summary>
        /// Method handles the click functionality for generating a yearly report.
        /// Given a year, a specific yearly report is generated for inventory items.
        /// This data source is then assigned to a report viewer in order to generate and display the report. 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnGenYearReport_OnClick(object sender, EventArgs e)
        {
            lblMasterError.Text = "";    //clear out any error messages

            //hide all reports and their containers
            divYearInv.Style.Value = "display:none;float:left;";
            divMonthInv.Style.Value = "display:none;float:left;";
            divQuarterInv.Style.Value = "display:none;float:left;";
            rvYearInv.Visible = false;
            rvMonthInv.Visible = false;
            rvQuarterInv.Visible = false;

            //Generate yearly report
            generateReport("YearInv");

            //re-enable all drop downs for other reports and disable this generate report button.
            //btnGenYearReport.Enabled = false;
            btnGenQuarterReport.Enabled = false;
            btnGenMonthReport.Enabled = false;
            ddlQuarter.Enabled = true;
            ddlMonth.Enabled = true;
        }
        /// <summary>
        /// Method handles the click functionality for generating a current inventory report.
        /// Given a filter type, a specific current inventory report is generated for items.
        /// This data source is then assigned to a report viewer in order to generate and display the report.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnGenCurInvReport_OnClick(object sender, EventArgs e)
        {
            lblMasterError.Text = "";        //clear out any error messages

            //hide all reports and their containers
            divCurInvAll.Style.Value = "display:none;float:left;";
            divCurInvItem.Style.Value = "display:none;float:left;";
            divCurInvSub.Style.Value = "display:none;float:left;";
            divCurInvCat.Style.Value = "display:none;float:left;";
            rvCurInvAll.Visible = false;
            rvCurInvItem.Visible = false;
            rvCurInvSub.Visible = false;
            rvCurInvCat.Visible = false;

            switch (ddlFilter.SelectedIndex)
            {
                case 0:
                    lblMasterError.Text = "Sorry, a report could not be generated for the given selection.  Please try again.";
                    break;
                case 1:
                    //Generate report on all current items
                    generateReport("CurInvAll");

                    //disable the advanced filter drop down.
                    ddlAdvFilter.Enabled = false;

                    break;
                case 2:
                    //Generate report on a specific item
                    generateReport("CurInvItem");

                    break;
                //case 3:
                //    //Generate report on a sub unit's items
                //    generateReport("CurInvSub");

                //    break;
                case 3:
                    //Generate report on a specific item category
                    generateReport("CurInvCat");

                    break;
                default:
                    lblMasterError.Text = "Sorry, a report could not be generated for the given selection.  Please try again.";
                    break;
            }

        }
        /// <summary>
        /// Method handles the click functionality for generating a item adjustments report.
        /// Given a starting date and end date, a specific item adjustments report is generated for items.
        /// This data source is then assigned to a report viewer in order to generate and display the report.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnGenItemAdjustReport_OnClick(object sender, EventArgs e)
        {
            lblMasterError.Text = "";        //clear out any error messages

            //hide all reports and their containers
            divItemAdjust.Style.Value = "display:none;float:left;";
            rvItemAdjust.Visible = false;

            //check to see if the dates are valid, and that the start date doesn't come after the end date.
            if (DateTime.TryParse(txtStartDate.Text, out startDate))
            {
                if (DateTime.TryParse(txtEndDate.Text, out endDate))
                {
                    if (startDate < endDate)
                    {
                        //Generate report on a item adjustments for a specific date range
                        generateReport("ItemAdjust");
                    }
                    else
                        lblMasterError.Text = "An error occurred while generating the report, the start date must come before the end date.";
                }
                else
                    lblMasterError.Text = "An error occurred while generating the report, the end date must be valid.";
            }
            else
                lblMasterError.Text = "An error occurred while generating the report, the start date must be valid.";
        }
        #endregion

        #region Report Viewer Method

        private void generateReport(string rvType)
        {
            if (rvType.Equals("CurInvAll"))
            {
                divCurInvAll.Style.Value = "display:block;float:left;"; //makes the report div visible
                rvCurInvAll.Visible = true;        //makes the report viewer visible

                /* Put the stored procedure result into a dataset */
                ds = presentation.ReportCurrentItems();
                /* Associate the DataSet  (now loaded with the stored procedure result) with the ReportViewer data source */
                dataSource = new ReportDataSource("dsCIA", ds.Tables[0]);

                rvCurInvAll.LocalReport.DataSources.Clear();
                rvCurInvAll.LocalReport.DataSources.Add(dataSource);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblMasterError.Text = "Sorry, there are no data for the current items or the report could not be generated.";
                }

                rvCurInvAll.LocalReport.Refresh();
            }
            else if (rvType.Equals("CurInvItem"))
            {
                divCurInvItem.Style.Value = "display:block;float:left;"; //makes the report div visible
                rvCurInvItem.Visible = true;        //makes the report viewer visible

                /* Put the stored procedure result into a dataset */
                ds = presentation.ReportCurrentItemByItemID(Convert.ToInt32(ddlAdvFilter.SelectedItem.Value));

                /* Associate the DataSet  (now loaded with the stored procedure result) with the ReportViewer data source */
                dataSource = new ReportDataSource("dsCII", ds.Tables[0]);

                rvCurInvItem.LocalReport.DataSources.Clear();
                rvCurInvItem.LocalReport.DataSources.Add(dataSource);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblMasterError.Text = "Sorry, there are no data for the item or the report could not be generated.";
                }

                rvCurInvItem.LocalReport.Refresh();
            }
            else if (rvType.Equals("CurInvSub"))
            {
                divCurInvSub.Style.Value = "display:block;float:left;"; //makes the report div visible
                rvCurInvSub.Visible = true;        //makes the report viewer visible

                /* Put the stored procedure result into a dataset */
                ds = presentation.ReportCurrentItemsBySubUnit(Convert.ToInt32(ddlAdvFilter.SelectedItem.Value));

                /* Associate the DataSet  (now loaded with the stored procedure result) with the ReportViewer data source */
                dataSource = new ReportDataSource("dsCISU", ds.Tables[0]);

                rvCurInvSub.LocalReport.DataSources.Clear();
                rvCurInvSub.LocalReport.DataSources.Add(dataSource);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblMasterError.Text = "Sorry, there are no data for the sub unit's items or the report could not be generated.";
                }

                rvCurInvSub.LocalReport.Refresh();
            }
            else if (rvType.Equals("CurInvCat"))
            {
                divCurInvCat.Style.Value = "display:block;float:left;"; //makes the report div visible
                rvCurInvCat.Visible = true;        //makes the report viewer visible

                /* Put the stored procedure result into a dataset */
                ds = presentation.ReportCurrentItemsByCategory(Convert.ToInt32(ddlAdvFilter.SelectedItem.Value));

                /* Associate the DataSet  (now loaded with the stored procedure result) with the ReportViewer data source */
                dataSource = new ReportDataSource("dsCIC", ds.Tables[0]);

                rvCurInvCat.LocalReport.DataSources.Clear();
                rvCurInvCat.LocalReport.DataSources.Add(dataSource);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblMasterError.Text = "Sorry, there are no data for the items in the category or the report could not be generated.";
                }

                rvCurInvCat.LocalReport.Refresh();
            }
            else if (rvType.Equals("MonthInv"))
            {
                divMonthInv.Style.Value = "display:block;float:left;"; //makes the report div visible
                rvMonthInv.Visible = true;        //makes the report viewer visible

                /* Put the stored procedure result into a dataset */
                ds = presentation.GetMonthlyReport(Convert.ToInt32(ddlMonth.SelectedItem.Value), Convert.ToInt32(ddlMRYear.SelectedItem.Text), preparedBy);

                /* Associate the DataSet  (now loaded with the stored procedure result) with the ReportViewer data source */
                dataSource = new ReportDataSource("dsMI", ds.Tables[0]);

                rvMonthInv.LocalReport.DataSources.Clear();
                rvMonthInv.LocalReport.DataSources.Add(dataSource);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblMasterError.Text = "Sorry, there are no data for the monthly report or the report could not be generated.";
                }

                rvMonthInv.LocalReport.Refresh();
            }
            else if (rvType.Equals("QuarterInv"))
            {
                divQuarterInv.Style.Value = "display:block;float:left;"; //makes the report div visible
                rvQuarterInv.Visible = true;        //makes the report viewer visible

                /* Put the stored procedure result into a dataset */
                ds = presentation.GetQuarterlyReport(Convert.ToInt32(ddlQuarter.SelectedItem.Value), Convert.ToInt32(ddlQRYear.SelectedItem.Text), preparedBy);

                /* Associate the DataSet  (now loaded with the stored procedure result) with the ReportViewer data source */
                dataSource = new ReportDataSource("dsQI", ds.Tables[0]);

                rvQuarterInv.LocalReport.DataSources.Clear();
                rvQuarterInv.LocalReport.DataSources.Add(dataSource);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblMasterError.Text = "Sorry, there are no data for the quarterly report or the report could not be generated.";
                }

                rvQuarterInv.LocalReport.Refresh();
            }
            else if (rvType.Equals("YearInv"))
            {
                divYearInv.Style.Value = "display:block;float:left;"; //makes the report div visible
                rvYearInv.Visible = true;        //makes the report viewer visible

                /* Put the stored procedure result into a dataset */
                ds = presentation.GetYearlyReport(Convert.ToInt32(ddlYear.SelectedItem.Text), preparedBy);

                /* Associate the DataSet  (now loaded with the stored procedure result) with the ReportViewer data source */
                dataSource = new ReportDataSource("dsYI", ds.Tables[0]);

                rvYearInv.LocalReport.DataSources.Clear();
                rvYearInv.LocalReport.DataSources.Add(dataSource);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblMasterError.Text = "Sorry, there are no data for the yearly report or the report could not be generated.";
                }

                rvYearInv.LocalReport.Refresh();
            }
            else if (rvType.Equals("ItemAdjust"))
            {
                divItemAdjust.Style.Value = "display:block;float:left;"; //makes the report div visible
                rvItemAdjust.Visible = true;        //makes the report viewer visible

                /* Put the stored procedure result into a dataset */
                ds = presentation.ReportItemAdjustments(startDate, endDate);

                /* Associate the DataSet  (now loaded with the stored procedure result) with the ReportViewer data source */
                dataSource = new ReportDataSource("dsIA", ds.Tables[0]);

                rvItemAdjust.LocalReport.DataSources.Clear();
                rvItemAdjust.LocalReport.DataSources.Add(dataSource);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblMasterError.Text = "Sorry, there are no data for the item adjustments report or the report could not be generated.";
                }

                rvItemAdjust.LocalReport.Refresh();
            }
        }

        #endregion

        #region Drop Down Methods
        /// <summary>
        /// This method handles the population of the advanced filter drop down 
        /// depending on the selection from this drop down, ddlFilter.
        /// Enables the Advanced Filter drop down, and enables the generate report button, depending on the selection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlFilter_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            switch (ddlFilter.SelectedIndex)
            {
                case 0:
                    break;
                case 1:     //All Items
                    ddlAdvFilter.Enabled = false;
                    break;
                case 2:     //Specific Item
                    ds = presentation.GetItems();
                    ddlAdvFilter.DataSource = ds.Tables[1];
                    ddlAdvFilter.DataTextField = "ItemName";
                    ddlAdvFilter.DataValueField = "ItemID";
                    ddlAdvFilter.DataBind();

                    ddlAdvFilter.Enabled = true;
                    break;
                //case 3:     //Sub Unit
                //    ds = presentation.GetSubUnits();
                //    ddlAdvFilter.DataSource = ds.Tables[1];
                //    ddlAdvFilter.DataTextField = "subUnitName";
                //    ddlAdvFilter.DataValueField = "subUnitID";
                //    ddlAdvFilter.DataBind();

                //    ddlAdvFilter.Enabled = true;
                //    break;
                case 3:     //Item Category
                    User user = (User)Session["LoggedInUser"];
                    int storeId = user.getStoreId();
                    ds = presentation.GetCategoryByStore(storeId);
                    ddlAdvFilter.DataSource = ds.Tables[1];
                    ddlAdvFilter.DataTextField = "itemCategoryName";
                    ddlAdvFilter.DataValueField = "itemCategoryID";
                    ddlAdvFilter.DataBind();

                    ddlAdvFilter.Enabled = true;
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// Method handles the selection of the month for the monthly report. 
        /// Basically enables the year drop down for the monthly report once a month has been selected.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlMonth_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlMonth.SelectedIndex != 0)
            {
                ddlMRYear.Enabled = true;
                btnGenQuarterReport.Enabled = false;
                btnGenYearReport.Enabled = false;
                btnGenMonthReport.Enabled = true;
            }
            else
            {
                ddlMRYear.Enabled = false;
                btnGenQuarterReport.Enabled = false;
                btnGenYearReport.Enabled = true;
                btnGenMonthReport.Enabled = false;
            }
        }
        /// <summary>
        /// Method handles the selection of the quarter for the quarterly report. 
        /// Basically enables the year drop down for the quarterly report once a quarter has been selected.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlQuarter_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlQuarter.SelectedIndex != 0)
            {
                ddlQRYear.Enabled = true;
                btnGenMonthReport.Enabled = false;
                btnGenYearReport.Enabled = false;
                btnGenQuarterReport.Enabled = true;
            }
            else
            {
                ddlQRYear.Enabled = false;
                btnGenMonthReport.Enabled = false;
                btnGenYearReport.Enabled = true;
                btnGenQuarterReport.Enabled = false;
            }
        }
        /// <summary>
        /// Method handles the selection of the year for the monthly report. 
        /// Basically enables the button for generating the report once a year has been selected.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlMRYear_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            btnGenMonthReport.Enabled = true;
        }
        /// <summary>
        /// Method handles the selection of the year for the quarterly report. 
        /// Basically enables the button for generating the report once a year has been selected.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlQRYear_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            btnGenQuarterReport.Enabled = true;
        }
        /// <summary>
        /// Method handles the selection of the year for the yearly report. 
        /// Basically enables the button for generating the report once a year has been selected.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlYear_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            btnGenYearReport.Enabled = true;
        }
        #endregion

        #region Session Methods
        private int GetStoreID()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getStoreId();
        }
        private string GetSessionID()
        {
            try
            {
                User lg = (User)Session["LoggedInUser"];
                return lg.getSessionId();
            }
            catch (Exception  ex)
            {
                ex.Message.ToString();
                return null;
            }
        }
        private string GetFirstName()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getFirstName();
        }
        private string GetLastName()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getLastName();
        }
        private bool GetIsAdmin()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getIsAdmin();
        }
        private bool GetIsGeneralManager()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getIsGeneralManager();
        }
        private bool GetIsStoreManager()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getIsStoreManager();
        }
        private bool GetIsStoreKeeper()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getIsStoreKeeper();
        }
        private bool GetIsSubUnitClerk()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getIsSubUnitClerk();
        }
        private bool GetIsAccounting()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getIsAccounting();
        }
        private bool GetIsProcurement()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getIsProcurement();
        }
        private bool GetIsCEO()
        {
            User lg = (User)Session["LoggedInUser"];
            return lg.getIsCEO();
        }
        #endregion
    }
}